package com.smartleanx.module.hrm.dal.mysql.welcomemessage;

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.smartleanx.framework.mybatis.core.mapper.BaseMapperX;
import com.smartleanx.module.hrm.dal.dataobject.welcomemessage.WelcomeMessageDO;
import org.apache.ibatis.annotations.Mapper;
import com.smartleanx.module.hrm.controller.admin.welcomemessage.vo.*;

/**
 * 欢迎语 Mapper
 *
 * @author 精益大师
 */
@Mapper
public interface WelcomeMessageMapper extends BaseMapperX<WelcomeMessageDO> {

    default PageResult<WelcomeMessageDO> selectPage(WelcomeMessagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WelcomeMessageDO>()
                .eqIfPresent(WelcomeMessageDO::getContent, reqVO.getContent())
                .eqIfPresent(WelcomeMessageDO::getStatus, reqVO.getStatus())
                .orderByDesc(WelcomeMessageDO::getId));
    }

    /**
     * 获取当前欢迎语
     *
     * @return
     */
    default WelcomeMessageDO getCurrentWelcomeMessage() {
        LambdaQueryWrapper<WelcomeMessageDO> queryWrapper = Wrappers.lambdaQuery();
        return selectOne(queryWrapper.last("limit 1"));
    }
}